#include "link_list.h"
#include "File.h"

// git 测试

Elenemt_data data[10] = 
{
    {.name = "唐三" , .sex = "男" , .age = 18 , .id = 1 , .sco = 60} , 
    {.name = "萧炎" , .sex = "男" , .age = 18 , .id = 3 , .sco = 60} , 
    {.name = "小舞" , .sex = "男" , .age = 18 , .id = 5 , .sco = 60} , 
    {.name = "牧尘" , .sex = "男" , .age = 18 , .id = 7 , .sco = 60} , 
    {.name = "熏儿" , .sex = "男" , .age = 18 , .id = 9 , .sco = 60} ,
};
Elenemt_data data2[10] = 
{
    {.name = "唐三" , .sex = "男" , .age = 18 , .id = 2 , .sco = 60} , 
    {.name = "萧炎" , .sex = "男" , .age = 18 , .id = 4 , .sco = 60} , 
    {.name = "小舞" , .sex = "男" , .age = 18 , .id = 6 , .sco = 60} , 
    {.name = "牧尘" , .sex = "男" , .age = 18 , .id = 8 , .sco = 60} , 
    {.name = "熏儿" , .sex = "男" , .age = 18 , .id = 10 , .sco = 60} ,
};


void link_list_func(void)
{
    // 初始化头节点
    link_list * list_1 = NULL;
    link_list * list_2 = NULL;
    init_link_list(&list_1);
    init_link_list(&list_2);

    /* ******************* 读取 ******************* */
   // File_scanf(list_1);
    //File_scanf(list_2);

    /* ******************* 合并 ******************* */
    merge_link_list(list_1 , list_2);

    
    /* ******************* 遍历 ******************* */
    print_link_list(list_1);

    /* ******************* 释放 ******************* */
    free_link_list(&list_1);
    free_link_list(&list_2);

}




void bubbleSortList(link_list *list) {
    if (list == NULL || list->next == NULL) {
        return;
    }
    int swapped;
    Node *ptr_1;
    Node *ptr_2;
    do {
        swapped = 0;
        ptr_1 = list->next;
        while (ptr_1 != NULL && ptr_1->next != NULL) 
        {
            ptr_2 = ptr_1->next;
            if (ptr_1->data.id > ptr_2->data.id) 
            {
                int temp = ptr_1->data.id;
                ptr_1->data.id = ptr_2->data.id;
                ptr_2->data.id = temp;
                swapped = 1;
            }

            ptr_1 = ptr_2;
        }
    } while (swapped);
}



void link_list_func2(void)
{
    link_list * list_1 = NULL;
    link_list * list_2 = NULL;
    init_link_list(&list_1);
    init_link_list(&list_2);
    printf("排序前\n");
    for (size_t i = 0; i < 5; i++)
    {
        insert_link_list(list_1,data[i],i+1);
    }
    print_link_list(list_1);

    for (size_t i = 0; i < 5; i++)
    {
        insert_link_list(list_2,data2[i],i+1);
    }
    print_link_list(list_2);
    
    merge_link_list(list_1 , list_2);
    
    bubbleSortList(list_1);
    printf("\n排序后\n");
    print_link_list(list_1);

}

int main(int argc, char const *argv[])
{
    link_list_func2();
    return 0;
}


